{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "37a358e3",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 方案1：逐个判断\n",
    "# 方案2：利用集合的交集查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "c4ade887",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "({'g': 2, 'd': 1, 'e': 2, 'f': 2, 'a': 1, 'c': 2},\n",
       " {'d': 3, 'c': 2, 'e': 3, 'f': 3, 'g': 1, 'b': 3},\n",
       " {'b': 3, 'd': 1, 'c': 3, 'e': 2, 'g': 2, 'a': 3})"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3个字典：\n",
    "from random import randint,sample\n",
    "d1={i:randint(1,3)for i in sample('abcdefg',randint(4,7))}\n",
    "d2={i:randint(1,3)for i in sample('abcdefg',randint(4,7))}\n",
    "d3={i:randint(1,3)for i in sample('abcdefg',randint(4,7))}\n",
    "d1,d2,d3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "af0b5913",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['g', 'd', 'e', 'c']"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 方案1：逐个判断\n",
    "#1.1\n",
    "[i for i in d1 if i in d2 and i in d3]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ab6e6b5f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['g', 'd', 'e', 'c']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1.2 \n",
    "dl=[d1,d2,d3]\n",
    "[i for i in dl[0] if all(map(lambda d: i in d,dl[1:]))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "dae98505",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 方案2：利用集合的交集查找"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "5a1c1596",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'c', 'd', 'e', 'g'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "from functools import reduce\n",
    "reduce(lambda a,b: a & b ,map(lambda x: x.keys(),dl))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4164ada1",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
